package com.itheima.controller.backend.reservation;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckGroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className CheckGroupController
 */
@RestController
@RequestMapping("/checkgroup")
@RequiredArgsConstructor
public class CheckGroupController {

    private final CheckGroupService checkGroupService;

    /**
     * 分页查询检查组
     * @param queryPageBean 分页条件
     * @return PageResult
     **/
    @PostMapping("/findPage")
    public PageResult getCheckGroupByPage(@RequestBody QueryPageBean queryPageBean) {
        return checkGroupService.getCheckGroupByPage(queryPageBean);
    }

    /**
     * 新增检查组
     * @param checkItemIds 检查项id集合
     * @param checkGroup 检查组对象
     * @return Result
     **/
    @PostMapping("/add")
    public Result addCheckGroup(@RequestParam("checkitemIds") List<Integer> checkItemIds,
                                @RequestBody CheckGroup checkGroup) {
        checkGroupService.addCheckGroup(checkItemIds, checkGroup);
        return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);
    }

    /**
     * 删除检查组
     * @param groupId 检查组id
     * @return Result
     **/
    @GetMapping("/deleteById")
    public Result deleteCheckGroupById(@RequestParam("id") Integer groupId) {
        checkGroupService.deleteCheckGroupById(groupId);
        return new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS);
    }

    /**
     * 编辑检查组
     * @param checkItemIds 检查项id集合
     * @param checkGroup 检查组对象
     * @return Result
     **/
    @PostMapping("/edit")
    public Result editCheckGroupById(@RequestParam("checkitemIds") List<Integer> checkItemIds,
                                     @RequestBody CheckGroup checkGroup){
        checkGroupService.editCheckGroupById(checkItemIds,checkGroup);
        return new Result(true,MessageConstant.EDIT_CHECKGROUP_SUCCESS);
    }

    /**
     * 根据检查组id查询检查组
     * @param groupId 检查组id
     * @return Result
     **/
    @GetMapping("/findById")
    public Result getCheckGroupById(@RequestParam("id") Integer groupId){
        CheckGroup checkGroup = checkGroupService.getCheckGroupById(groupId);
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkGroup);
    }

    /**
     * 根据套餐id查询套餐所对应的检查组id集合
     * @param setMealId 套餐id
     * @return Result
     **/
    @GetMapping("/findCheckGroupIdsBySetmealId")
    public Result findCheckGroupIdsBySetmealId(@RequestParam("setmealId") Integer setMealId){
        List<Integer> checkGroupIds = checkGroupService.findCheckGroupIdsBySetmealId(setMealId);
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkGroupIds);
    }

    /**
     * 查询所有检查组
     * @return Result
     **/
    @GetMapping("/findAll")
    public Result getAllCheckGroup(){
        List<CheckGroup> checkGroups = checkGroupService.getAllCheckGroup();
        return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkGroups);
    }
}
